package nc.ui.uif2.actions;

import java.awt.event.ActionEvent;
import java.util.List;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import nc.ui.querytemplate.querytree.IIconDecorator;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.UIState;
import nc.ui.uif2.model.BillTableModel;

public class EditTableRowAction extends NCAction
{
  private static final long serialVersionUID = -7046357038460805095L;
  private BillTableModel model;
  public static final Icon EDIT_ICON = new ImageIcon(IIconDecorator.class.getResource("/images/reportquery/toolbar/edit.gif"));

  public EditTableRowAction()
  {
    ActionInitializer.initializeAction(this, 3);
    putValue("SmallIcon", EDIT_ICON);
  }

  public void doAction(ActionEvent e) throws Exception
  {
    this.model.setUiState(UIState.EDIT);
  }

  protected boolean isActionEnable()
  {
    if (this.model.getRows().size() <= 0) {
      return false;
    }

    return (UIState.NOT_EDIT == this.model.getUiState()) || (UIState.INIT == this.model.getUiState());
  }

  public BillTableModel getModel()
  {
    return this.model;
  }

  public void setModel(BillTableModel model) {
    this.model = model;
    model.addAppEventListener(this);
  }
}